home *** CD-ROM | disk | FTP | other *** search
/ OpenGL Superbible (2nd Edition) / OpenGL SuperBible e2.iso / tools / FLTK-1.0.6 / test / input.cxx < prev    next >
Encoding:
C/C++ Source or Header  |  1999-01-07  |  3.9 KB  |  122 lines

  1. //
  2. // "$Id: input.cxx,v 1.5 1999/01/07 19:17:56 mike Exp $"
  3. //
  4. // Input field test program for the Fast Light Tool Kit (FLTK).
  5. //
  6. // Copyright 1998-1999 by Bill Spitzak and others.
  7. //
  8. // This library is free software; you can redistribute it and/or
  9. // modify it under the terms of the GNU Library General Public
  10. // License as published by the Free Software Foundation; either
  11. // version 2 of the License, or (at your option) any later version.
  12. //
  13. // This library is distributed in the hope that it will be useful,
  14. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  16. // Library General Public License for more details.
  17. //
  18. // You should have received a copy of the GNU Library General Public
  19. // License along with this library; if not, write to the Free Software
  20. // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
  21. // USA.
  22. //
  23. // Please report all bugs and problems to "fltk-bugs@easysw.com".
  24. //
  25.  
  26. #include <stdio.h>
  27. #include <FL/Fl.H>
  28. #include <FL/Fl_Window.H>
  29. #include <FL/Fl_Input.H>
  30. #include <FL/Fl_Float_Input.H>
  31. #include <FL/Fl_Int_Input.H>
  32. #include <FL/Fl_Secret_Input.H>
  33. #include <FL/Fl_Multiline_Input.H>
  34. #include <FL/Fl_Button.H>
  35. #include <FL/Fl_Toggle_Button.H>
  36. #include <FL/Fl_Color_Chooser.H>
  37.  
  38. void cb(Fl_Widget *ob) {
  39.   printf("Callback for %s '%s'\n",ob->label(),((Fl_Input*)ob)->value());
  40. }
  41.  
  42. int when = 0;
  43. Fl_Input *input[5];
  44.  
  45. void toggle_cb(Fl_Widget *o, long v) {
  46.   if (((Fl_Toggle_Button*)o)->value()) when |= v; else when &= ~v;
  47.   for (int i=0; i<5; i++) input[i]->when(when);
  48. }
  49.  
  50. void test(Fl_Input *i) {
  51.   if (i->changed()) {
  52.     i->clear_changed(); printf("%s '%s'\n",i->label(),i->value());
  53.   }
  54. }
  55.  
  56. void button_cb(Fl_Widget *,void *) {
  57.   for (int i=0; i<5; i++) test(input[i]);
  58. }
  59.  
  60. void color_cb(Fl_Widget* button, void* v) {
  61.   Fl_Color c;
  62.   switch ((int)v) {
  63.   case 0: c = FL_WHITE; break;
  64.   case 1: c = FL_SELECTION_COLOR; break;
  65.   default: c = FL_BLACK; break;
  66.   }
  67.   uchar r,g,b; Fl::get_color(c, r,g,b);
  68.   if (fl_color_chooser(0,r,g,b)) {
  69.     Fl::set_color(c,r,g,b); Fl::redraw();
  70.     button->labelcolor(contrast(FL_BLACK,c));
  71.     button->redraw();
  72.   }
  73. }
  74.  
  75. int main(int argc, char **argv) {
  76.   Fl_Window *window = new Fl_Window(400,400);
  77.  
  78.   int y = 10;
  79.   input[0] = new Fl_Input(70,y,300,30,"Normal:"); y += 35;
  80.   // input[0]->cursor_color(FL_SELECTION_COLOR);
  81.   //  input[0]->maximum_size(20);
  82.   // input[0]->static_value("this is a testgarbage");
  83.   input[1] = new Fl_Float_Input(70,y,300,30,"Float:"); y += 35;
  84.   input[2] = new Fl_Int_Input(70,y,300,30,"Int:"); y += 35;
  85.   input[3] = new Fl_Secret_Input(70,y,300,30,"Secret:"); y += 35;
  86.   input[4] = new Fl_Multiline_Input(70,y,300,100,"Multiline:"); y += 105;
  87.  
  88.   for (int i = 0; i < 4; i++) {
  89.     input[i]->when(0); input[i]->callback(cb);
  90.   }
  91.   int y1 = y;
  92.  
  93.   Fl_Button *b;
  94.   b = new Fl_Toggle_Button(10,y,200,25,"FL_WHEN_&CHANGED");
  95.   b->callback(toggle_cb, FL_WHEN_CHANGED); y += 25;
  96.   b = new Fl_Toggle_Button(10,y,200,25,"FL_WHEN_&RELEASE");
  97.   b->callback(toggle_cb, FL_WHEN_RELEASE); y += 25;
  98.   b = new Fl_Toggle_Button(10,y,200,25,"FL_WHEN_&ENTER_KEY");
  99.   b->callback(toggle_cb, FL_WHEN_ENTER_KEY); y += 25;
  100.   b = new Fl_Toggle_Button(10,y,200,25,"FL_WHEN_&NOT_CHANGED");
  101.   b->callback(toggle_cb, FL_WHEN_NOT_CHANGED); y += 25;
  102.   y += 5;
  103.   b = new Fl_Button(10,y,200,25,"&print changed()");
  104.   b->callback(button_cb);
  105.  
  106.   b = new Fl_Button(220,y1,100,25,"color"); y1 += 25;
  107.   b->color(input[0]->color()); b->callback(color_cb, (void*)0);
  108.   b = new Fl_Button(220,y1,100,25,"selection_color"); y1 += 25;
  109.   b->color(input[0]->selection_color()); b->callback(color_cb, (void*)1);
  110.   b = new Fl_Button(220,y1,100,25,"textcolor"); y1 += 25;
  111.   b->color(input[0]->textcolor()); b->callback(color_cb, (void*)2);
  112.   b->labelcolor(contrast(FL_BLACK,b->color()));
  113.  
  114.   window->end();
  115.   window->show(argc,argv);
  116.   return Fl::run();
  117. }
  118.  
  119. //
  120. // End of "$Id: input.cxx,v 1.5 1999/01/07 19:17:56 mike Exp $".
  121. //
  122.